// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/AlarmApi'

import OneClass from '@api/base/model/AlarmDetailQueryReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne(one) {
    return one.id
  },
  async getOne({ id }, TIP = '查询详情') {
    const DTO = CORE.grpcDTO(OneClass, { id })
    const resp = await CORE.grpc(TIP, CLIENT, 'detail', DTO)
    return { ...resp.content, cameraList: resp.cameraList || [] }
  },
  transOne(obj) {
    const fileList = obj.messageAlarmFileDto || []
    obj.imageList = fileList.filter((item) => item.fileType === 1)
    obj.videoList = fileList.filter((item) => item.fileType === 3)

    const dealFileList = obj.alarmResolveState === 1 ? [] : obj.messageAlarmDealFileDto || []
    obj.dealImageList = dealFileList.filter((item) => item.fileType === 1)

    if (obj.alarmResolveState === 1) {
      obj.dealType = 0
      obj.dealUserName = obj.dealUserPhone = obj.dealTime = obj.dealDesc = obj.dealWorkOrder = ''
    }

    return obj
  },
}
